<?php
declare (strict_types = 1);
namespace app\admin\controller;
use app\common\controller\Backend;
use think\facade\Db;
use think\facade\View;

class Album extends Backend
{
    public function initialize() {
        parent::initialize();
        $this->_mod  = new \app\admin\model\Album();
    }

    public function ajax_upload_img(){
        $file = request()->file('file');  //这里‘file’是你提交时的name
        $paths = 'album';
        try{
            $saveName = \think\facade\Filesystem::disk('public')->putFile( $paths, $file,
                function () use ($file){
                    switch ('date') {
                        case 'date':
                            $fileName = date('YmdHis').rand(1,9999).rand(1,9999);
                            break;
                        // 此项即为：保留原始文件名+日期方式
                        case 'original':
                            $fileName = str_replace('.'.$file->getOriginalExtension(),'',$file->getOriginalName().date('YmdHis'));
                            break;
                        default:
                            $fileName = uniqid();
                            break;
                    }
                    return $fileName;
                });//保存文件名
            $f_name = explode('/',$saveName);
            $saveName = end($f_name);
            $arr = ['status' =>1 ,'info' => $saveName,'img_url'=>upload_url($saveName,  $paths)];
            return json($arr);   				//返回标准json格式
        }catch (\Exception $e) {
            return $this->exceptionHandle($e,'上传失败!' . $e->getMessage(),'json','');
        }
    }

    public function _after_delete($ids){
        $where[] = array('zjid', 'in', $ids);
        Db::name('doc_con')->where($where)->update(['zjid'=>0]);
    }

}


